# -*- coding: utf-8 -*-

# Autor: Pedro Godinho, n.º 6355
# Data: 11/12/2011

from BeautifulSoup import BeautifulSoup
import urllib

class ContadorTag:
    '''
    Classe responsável por fazer a contagem das Tag's
    '''
    @staticmethod
    def contadorTag(url):
        lista = []
        nome = urllib.urlopen(str(url)) 
        soup = BeautifulSoup(nome)
        
        try:
            total = 0
            for h1 in soup.h1:
                total = total + 1 
                pass
            lista.append( "Existem " + str(total) + " tags <H1>")
        except:
            lista.append( "Nao existem tags <H1>")
            pass

        try:
            total = 0
            for h2 in soup.h2:
                total = total + 1
                pass
            lista.append( "Existem " + str(total) + " tags <H2>")
        except:
            lista.append( "Nao existem tags <H2>")
            pass

        try:
            total = 0
            for h3 in soup.h3:
                total = total + 1
                pass
            lista.append( "Existem " + str(total) + " tags <H3>")
        except:
            lista.append( "Nao existem tags <H3>")
            pass

        try:
            total = 0
            for div in soup.div:
                total = total + 1
                pass
            lista.append( "Existem " + str(total) + " tags <Div>")
        except:
            lista.append( "Nao existem tags <Div>")
            pass

        try:
            total = 0
            for p in soup.p:
                total = total + 1
                pass
            lista.append( "Existem " + str(total) + " tags <P>")
        except:
            lista.append( "Não existem tags <P>")
            pass

        try:
            total = 0
            for ul in soup.ul:
                total = total + 1
                pass
            lista.append( "Existem " + str(total) + " tags <UL>")
        except:
            lista.append( "Nao existem tags <UL>")
            pass

        try:
            total = 0
            for ol in soup.ol:
                total = total + 1
                pass
            lista.append( "Existem " + str(total) + " tags <OL>")
        except:
            lista.append( "Nao existem tags <OL>")
            pass


        return lista
